package com.dawnling.greendaodemo.greendao.gen;

import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;

import com.dawnling.greendaodemo.bean.UserChildBean;
import com.dawnling.greendaodemo.converter.ObjectConverter;
import com.dawnling.greendaodemo.converter.ObjectListConverter;
import com.dawnling.greendaodemo.converter.StringListConverter;
import java.util.List;

import com.dawnling.greendaodemo.bean.UserBean;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "USER_BEAN".
*/
public class UserBeanDao extends AbstractDao<UserBean, Long> {

    public static final String TABLENAME = "USER_BEAN";

    /**
     * Properties of entity UserBean.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "Id", true, "_id");
        public final static Property Data = new Property(1, String.class, "data", false, "DATA");
        public final static Property Url = new Property(2, String.class, "url", false, "URL");
        public final static Property Name = new Property(3, String.class, "name", false, "NAME");
        public final static Property List = new Property(4, String.class, "list", false, "LIST");
        public final static Property UserChildBeanList = new Property(5, String.class, "userChildBeanList", false, "USER_CHILD_BEAN_LIST");
        public final static Property UserChildBean = new Property(6, String.class, "userChildBean", false, "USER_CHILD_BEAN");
    }

    private final StringListConverter listConverter = new StringListConverter();
    private final ObjectListConverter userChildBeanListConverter = new ObjectListConverter();
    private final ObjectConverter userChildBeanConverter = new ObjectConverter();

    public UserBeanDao(DaoConfig config) {
        super(config);
    }
    
    public UserBeanDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"USER_BEAN\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: Id
                "\"DATA\" TEXT," + // 1: data
                "\"URL\" TEXT," + // 2: url
                "\"NAME\" TEXT," + // 3: name
                "\"LIST\" TEXT," + // 4: list
                "\"USER_CHILD_BEAN_LIST\" TEXT," + // 5: userChildBeanList
                "\"USER_CHILD_BEAN\" TEXT);"); // 6: userChildBean
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"USER_BEAN\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, UserBean entity) {
        stmt.clearBindings();
 
        Long Id = entity.getId();
        if (Id != null) {
            stmt.bindLong(1, Id);
        }
 
        String data = entity.getData();
        if (data != null) {
            stmt.bindString(2, data);
        }
 
        String url = entity.getUrl();
        if (url != null) {
            stmt.bindString(3, url);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(4, name);
        }
 
        List list = entity.getList();
        if (list != null) {
            stmt.bindString(5, listConverter.convertToDatabaseValue(list));
        }
 
        List userChildBeanList = entity.getUserChildBeanList();
        if (userChildBeanList != null) {
            stmt.bindString(6, userChildBeanListConverter.convertToDatabaseValue(userChildBeanList));
        }
 
        UserChildBean userChildBean = entity.getUserChildBean();
        if (userChildBean != null) {
            stmt.bindString(7, userChildBeanConverter.convertToDatabaseValue(userChildBean));
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, UserBean entity) {
        stmt.clearBindings();
 
        Long Id = entity.getId();
        if (Id != null) {
            stmt.bindLong(1, Id);
        }
 
        String data = entity.getData();
        if (data != null) {
            stmt.bindString(2, data);
        }
 
        String url = entity.getUrl();
        if (url != null) {
            stmt.bindString(3, url);
        }
 
        String name = entity.getName();
        if (name != null) {
            stmt.bindString(4, name);
        }
 
        List list = entity.getList();
        if (list != null) {
            stmt.bindString(5, listConverter.convertToDatabaseValue(list));
        }
 
        List userChildBeanList = entity.getUserChildBeanList();
        if (userChildBeanList != null) {
            stmt.bindString(6, userChildBeanListConverter.convertToDatabaseValue(userChildBeanList));
        }
 
        UserChildBean userChildBean = entity.getUserChildBean();
        if (userChildBean != null) {
            stmt.bindString(7, userChildBeanConverter.convertToDatabaseValue(userChildBean));
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public UserBean readEntity(Cursor cursor, int offset) {
        UserBean entity = new UserBean( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // Id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // data
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // url
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // name
            cursor.isNull(offset + 4) ? null : listConverter.convertToEntityProperty(cursor.getString(offset + 4)), // list
            cursor.isNull(offset + 5) ? null : userChildBeanListConverter.convertToEntityProperty(cursor.getString(offset + 5)), // userChildBeanList
            cursor.isNull(offset + 6) ? null : userChildBeanConverter.convertToEntityProperty(cursor.getString(offset + 6)) // userChildBean
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, UserBean entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setData(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setUrl(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setName(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setList(cursor.isNull(offset + 4) ? null : listConverter.convertToEntityProperty(cursor.getString(offset + 4)));
        entity.setUserChildBeanList(cursor.isNull(offset + 5) ? null : userChildBeanListConverter.convertToEntityProperty(cursor.getString(offset + 5)));
        entity.setUserChildBean(cursor.isNull(offset + 6) ? null : userChildBeanConverter.convertToEntityProperty(cursor.getString(offset + 6)));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(UserBean entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(UserBean entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(UserBean entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
}
